#ifndef USRAI_H
#define USRAI_H

#include "AI.h"

extern tagGame tagUsrGame;
extern ins UsrIns;
/*##########DO NOT MODIFY THE CODE ABOVE##########*/

class UsrAI : public AI
{
public:
    UsrAI() {
        this->id = 0;
        this->checkShipNum=0;
    }
    ~UsrAI() {}

    static int stage;
    int checkShipNum;
    unordered_set<int> seenShipSNs;

private:
    void processData() override;
    tagInfo getInfo() { return tagUsrGame.getInfo(); }
    int AddToIns(instruction ins) override
    {
        UsrIns.lock.lock();
        ins.id = UsrIns.g_id;
        UsrIns.g_id++;
        UsrIns.instructions.push(ins);
        UsrIns.lock.unlock();
        return ins.id;
    }
    void clearInsRet() override
    {
        tagUsrGame.clearInsRet();
    }
    /*##########DO NOT MODIFY THE CODE IN THE CLASS##########*/
    bool tryBuildBuilding(int buildingType, int requiredWood, int maxCount, int reqiredBuilding, int is_settler = 0);
    //

    void autoAttackEnemy();
    void getDebugTexts();
    void checkStage();
    void getMapInfo();
    void stage_01_test();
    void stage_02_test();
    void stage_03_test();
    void stage_04_test();
    void getObjectTable();
    void getFarmerState();
    bool getBuildingAction(tagBuilding &building, int action);
    void moveAlongCoast(tagFarmer &boat);
    void findFish();
    void getShipVisit();
    void checkMyLand();
    void checkEnemyLand();
    void getMyCoast();
    void getEnemyCoast();
    pair<int, int> countAvgLoc();
    pair<int, int> guessEnemyLoc();
    void assignFarmerRoles01();
    void assignFarmerRoles02();
    void assignFarmerRoles03();
    void farmerDoWork01();
    void farmerDoWork02();
    void farmerDoWork03();
    void buildLogic01();
    void buildLogic02();
    void buildLogic03();
    void boatFishingLogic();
    void warshipDetectLogic();
    void warshipAttackLogic();
    void boatTransport();
    void updateShipStatus();
    void buildDefensiveTowers(); // 新增：建造防御塔的逻辑
    void manageGroundForces(); // 新增：管理地面单位和军营
    pair<int, int> bfsSearchMyCoast(tagObj& origin);

    // BFS and helper functions
    pair<pair<int, int>, int> bfsSearch(tagObj &origin, int type);
    pair<pair<int, int>, int> bfsDockSearch(tagObj &origin);
    pair<int, int> bfsSearchBuilding(tagObj &origin, int size, int num);
    vector<pair<int, int>> sailingBfsSearch(tagObj &origin, int targetType);
    vector<pair<int, int>> shipBfsSearch(tagObj &origin, int targetType);
    vector<pair<int, int>> bfsSearchEnemyLand(tagObj &origin, pair<int, int> &dest);
    pair<int, int> bfsSearchEnemyCoast(tagObj& origin);
    int getBuildingSize(int buildingType);
};

/*##########YOUR CODE BEGINS HERE##########*/

/*##########YOUR CODE ENDS HERE##########*/
#endif // USRAI_H
